<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of show_sigma</title>
  <meta name="keywords" content="show_sigma">
  <meta name="description" content="function [] = show_sigma(meshfile,bathfile,sigmafile)">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../index.html">Home</a> &gt;  <a href="index.html">utilities</a> &gt; show_sigma.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for utilities&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->

<h1>show_sigma
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function [] = show_sigma(meshfile,bathfile,sigmafile)</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>This is a script file. </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment">function [] = show_sigma(meshfile,bathfile,sigmafile) 
 plot a sigma distribution along a user-selected line

 function [] = show_sigma(meshfile,bathfile,sigmafile) 

 DESCRIPTION:
    plot a sigma distribution along a user-selected line

 INPUT:
    meshfile:   fvcom grid file
    bathfile:   fvcom bathymetry file
    sigmafile:  fvcom sigma distribution file

 OUTPUT:

 EXAMPLE USAGE
    show_sigma('tst_grd.dat','tst_dep.dat','sigma.dat') 

 Author(s):  
    Geoff Cowles (University of Massachusetts Dartmouth)

 Revision history
   
==============================================================================</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="sigma_gen.html" class="code" title="function dist = sigma_gen(nlev,dl,du,kl,ku,zkl,zku,h,hmin)">sigma_gen</a>	</li></ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <span class="comment">%function [] = show_sigma(meshfile,bathfile,sigmafile)</span>
0002 <span class="comment">% plot a sigma distribution along a user-selected line</span>
0003 <span class="comment">%</span>
0004 <span class="comment">% function [] = show_sigma(meshfile,bathfile,sigmafile)</span>
0005 <span class="comment">%</span>
0006 <span class="comment">% DESCRIPTION:</span>
0007 <span class="comment">%    plot a sigma distribution along a user-selected line</span>
0008 <span class="comment">%</span>
0009 <span class="comment">% INPUT:</span>
0010 <span class="comment">%    meshfile:   fvcom grid file</span>
0011 <span class="comment">%    bathfile:   fvcom bathymetry file</span>
0012 <span class="comment">%    sigmafile:  fvcom sigma distribution file</span>
0013 <span class="comment">%</span>
0014 <span class="comment">% OUTPUT:</span>
0015 <span class="comment">%</span>
0016 <span class="comment">% EXAMPLE USAGE</span>
0017 <span class="comment">%    show_sigma('tst_grd.dat','tst_dep.dat','sigma.dat')</span>
0018 <span class="comment">%</span>
0019 <span class="comment">% Author(s):</span>
0020 <span class="comment">%    Geoff Cowles (University of Massachusetts Dartmouth)</span>
0021 <span class="comment">%</span>
0022 <span class="comment">% Revision history</span>
0023 <span class="comment">%</span>
0024 <span class="comment">%==============================================================================</span>
0025 meshfile = <span class="string">'tst_grd.dat'</span>;
0026 bathfile = <span class="string">'tst_dep.dat'</span>;
0027 sigmafile = <span class="string">'sigma.dat'</span>;
0028 close all;
0029 
0030 <span class="comment">% read the mesh</span>
0031 fid = fopen(meshfile,<span class="string">'r'</span>);
0032 <span class="keyword">if</span>(fid  &lt; 0)
0033   error([<span class="string">'file: '</span> meshfile <span class="string">' does not exist'</span>]);
0034 <span class="keyword">end</span>;
0035 C = textscan(fid, <span class="string">'%s %s %s %d'</span>, 1);
0036 Nverts = C{4};
0037 C = textscan(fid, <span class="string">'%s %s %s %d'</span>, 1);
0038 Nelems = C{4};
0039 x = zeros(Nverts,3);
0040 tri = zeros(Nelems,3);
0041 fprintf(<span class="string">'Nverts: %d\n'</span>,Nverts)
0042 fprintf(<span class="string">'Nelems: %d\n'</span>,Nelems)
0043 <span class="keyword">for</span> i=1:Nelems 
0044   C = textscan(fid, <span class="string">'%d %d %d %d %d'</span>, 1);
0045   tri(i,1) = C{2}; 
0046   tri(i,2) = C{3}; 
0047   tri(i,3) = C{4}; 
0048 <span class="keyword">end</span>;
0049 <span class="keyword">for</span> i=1:Nverts 
0050   C = textscan(fid, <span class="string">'%d %f %f %f '</span>, 1);
0051   x(i,1) = C{2}; 
0052   x(i,2) = C{3}; 
0053 <span class="keyword">end</span>;
0054 
0055 <span class="comment">% read the bathy</span>
0056 fid = fopen(bathfile,<span class="string">'r'</span>);
0057 <span class="keyword">if</span>(fid  &lt; 0)
0058   error([<span class="string">'file: '</span> bathfile <span class="string">' does not exist'</span>]);
0059 <span class="keyword">end</span>;
0060 C = textscan(fid, <span class="string">'%s %s %s %d'</span>, 1);
0061 <span class="keyword">for</span> i=1:Nverts
0062   C = textscan(fid, <span class="string">'%f %f %f '</span>, 1);
0063   x(i,3) = C{3};
0064 <span class="keyword">end</span>;
0065 
0066 fprintf(<span class="string">'min topography %f\n'</span>,min(x(:,3)));
0067 fprintf(<span class="string">'max topography %f\n'</span>,max(x(:,3)));
0068 
0069 <span class="comment">% read the sigma file</span>
0070 fid = fopen(sigmafile,<span class="string">'r'</span>);
0071 <span class="keyword">if</span>(fid  &lt; 0)
0072   error([<span class="string">'file: '</span> sigmafile <span class="string">' does not exist'</span>]);
0073 <span class="keyword">end</span>;
0074 C = textscan(fid, <span class="string">'%s %s %s %s %s %d'</span>, 1);
0075 nlev = C{6};
0076 C = textscan(fid, <span class="string">'%s %s %s %s %s'</span>, 1);
0077 sigtype = char(C{5});
0078 C = textscan(fid, <span class="string">'%s %s %f'</span>, 1);
0079 du = C{3};
0080 C = textscan(fid, <span class="string">'%s %s %f'</span>, 1);
0081 dl = C{3};
0082 C = textscan(fid, <span class="string">'%s %s %s %s %f'</span>, 1);
0083 min_constant_depth = C{5};
0084 C = textscan(fid, <span class="string">'%s %s %d'</span>, 1);
0085 ku = C{3};
0086 C = textscan(fid, <span class="string">'%s %s %d'</span>, 1);
0087 kl = C{3};
0088 C = textscan(fid, <span class="string">'%s %s %f %f %f %f %f %f %f %f %f %f %f'</span>, 1);
0089 <span class="keyword">for</span> i=1:ku
0090  zku(i) = C{2+i};
0091 <span class="keyword">end</span>;
0092 C = textscan(fid, <span class="string">'%s %s %f %f %f %f %f %f %f %f %f %f %f'</span>, 1);
0093 <span class="keyword">for</span> i=1:kl
0094  zkl(i) = C{2+i};
0095 <span class="keyword">end</span>;
0096 
0097 fprintf(<span class="string">'nlev %d\n'</span>,nlev)
0098 fprintf(<span class="string">'sigtype %s\n'</span>,sigtype)
0099 fprintf(<span class="string">'du %d\n'</span>,du)
0100 fprintf(<span class="string">'dl %d\n'</span>,dl)
0101 fprintf(<span class="string">'min_constant_depth %f\n'</span>,min_constant_depth)
0102 fprintf(<span class="string">'ku %d\n'</span>,ku)
0103 fprintf(<span class="string">'kl %d\n'</span>,kl)
0104 fprintf(<span class="string">'zku %d\n'</span>,zku)
0105 fprintf(<span class="string">'zkl %d\n'</span>,zkl)
0106 
0107 
0108 
0109 <span class="comment">% generate the sigma coordinates</span>
0110 fprintf(<span class="string">'select two endpoints of a transect'</span>)
0111 patch(<span class="string">'Vertices'</span>,[x(:,1),x(:,2)],<span class="string">'Faces'</span>,tri,<span class="keyword">...</span>
0112        <span class="string">'Cdata'</span>,x(:,3),<span class="string">'edgecolor'</span>,<span class="string">'interp'</span>,<span class="string">'facecolor'</span>,<span class="string">'interp'</span>);
0113 axis equal
0114 
0115 <span class="comment">% plot to get a line</span>
0116 <span class="comment">%fprintf('select two end points of a transect with your mouse');</span>
0117 [xt,yt] = ginput(2);
0118 hold on
0119 
0120 npts = 25;
0121 ds = (xt(2)-xt(1))/(npts-1);
0122 xline = xt(1):ds:xt(2);
0123 ds = (yt(2)-yt(1))/(npts-1);
0124 yline = yt(1):ds:yt(2);
0125 plot(xline,yline,<span class="string">'w+'</span>)
0126 sline(1) = 0.;
0127 <span class="keyword">for</span> i=2:npts
0128   sline(i) = sline(i-1) + sqrt(   (xline(i)-xline(i-1))^2 + (yline(i)-yline(i-1))^2);
0129 <span class="keyword">end</span>;
0130 
0131 <span class="comment">% interpolate the bathymetry along the line</span>
0132 [zline] = griddata(x(:,1),x(:,2),x(:,3),xline,yline);
0133 
0134 figure
0135 plot(sline,-zline)
0136 
0137 <span class="comment">% generate the sigma coordinates along the line</span>
0138 xslice = zeros(npts,nlev);
0139 yslice = zeros(npts,nlev);
0140 
0141 <span class="comment">% calculate the sigma distributions along the transect</span>
0142 <span class="keyword">if</span>(max(sigtype(1:3)==<span class="string">'gen'</span>) || max(sigtype(1:3)==<span class="string">'GEN'</span>))
0143   <span class="keyword">for</span> i=1:npts
0144      z(i,1:nlev) = <a href="sigma_gen.html" class="code" title="function dist = sigma_gen(nlev,dl,du,kl,ku,zkl,zku,h,hmin)">sigma_gen</a>(nlev,dl,du,kl,ku,zkl,zku,zline(i),min_constant_depth);
0145   <span class="keyword">end</span>;
0146 <span class="keyword">elseif</span>(max(sigtype(1:3)==<span class="string">'uni'</span>) || max(sigtype(1:3)==<span class="string">'UNI'</span>))
0147   <span class="keyword">for</span> i=1:npts
0148     z(i,1:nlev) = 0:-1/double(nlev-1):-1; 
0149   <span class="keyword">end</span>;
0150 <span class="keyword">else</span>
0151   error(<span class="string">'cant do that sigtype'</span>)
0152 <span class="keyword">end</span>;
0153 
0154 
0155 
0156 <span class="keyword">for</span> i=1:npts
0157   xslice(i,1:nlev) = sline(i);
0158   yslice(i,1:nlev) = z(i,1:nlev)*zline(i);
0159 <span class="keyword">end</span>;
0160 
0161 
0162 <span class="comment">% plot the mesh along the transect</span>
0163 <span class="keyword">for</span> k=1:nlev
0164   plot(xslice(:,k),yslice(:,k),<span class="string">'k'</span>); hold on;
0165 <span class="keyword">end</span>;
0166 <span class="keyword">for</span> k=1:npts
0167   plot(xslice(k,:),yslice(k,:),<span class="string">'k'</span>); hold on;
0168 <span class="keyword">end</span>;
0169 axis([xslice(1,1),xslice(<span class="keyword">end</span>,1),min(yslice(:,end)),5])
0170 title(<span class="string">'sigma distribution along the transect'</span>);
0171 
0172</pre></div>
<hr><address>Generated on Wed 02-Nov-2011 21:58:00 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>